<?php
namespace app\admin\controller;

use app\common\controller\AdminBase;

/**
* 职位管理
*/
class Jianli extends AdminBase
{
	
	protected function _initialize()
	{
		parent::_initialize();
	}
	public function index(){
		$res = db('jianli')->find(1);
        $res['title'] = json_decode($res['title'],true);
		return $this->fetch('index',['row'=>$res]);
	}
	public function update(){
 		if($this->request->isPost()) {
            $data = input('post.');
            $data['title'] = json_encode($_POST['title'],JSON_UNESCAPED_UNICODE);
            if (db('jianli')->update($data) !== false) {
                $this->success('更新成功', 'index');
            } else {
                $this->error('更新失败');
            }
        }
	}
	/*
	 * 更新'0'或'1'
	 */
	public function flag($id){
        if (request()->isPost()) {
            $data = input('post.');
            if (db('jianli')->where(['id' => $id])->update($data) !== false) {
                $this->success('更新成功');
            } else {
                $this->error('更新失败');
            }
        }
    }
    public function delete($id = 0, $ids = [])
    {
        $id = $ids ? $ids : $id;
        if ($id) {
            if (db('job')->delete($id)) {
                $this->success('删除成功');
            } else {
                $this->error('删除失败');
            }
        } else {
            $this->error('请选择需要删除的项目');
        }
    }
}